%{

#include <stdio.h>
#include "Common.h"
#include "parser.tab.h"


using namespace std;

#define update_location   { yylloc->first_column = yylloc->last_column + 1; yylloc->last_column += yyleng; }

%}

%option yylineno
%option bison-bridge
%option bison-locations
%option noyywrap
%option nounput


%%

"<nome>"					{update_location; return TAG_NAME_START;}
"</nome>"					{update_location; return TAG_NAME_END;}
"<versao>"					{update_location; return TAG_VERSION_START;}
"</versao>"					{update_location; return TAG_VERSION_END;}
"<variavel>"				{update_location; return TAG_VARIABLE_START;}
"</variavel>"				{update_location; return TAG_VARIABLE_END;}
"<regras>"					{update_location; return TAG_RULES_START;}
"</regras>"					{update_location; return TAG_RULES_END;}
"<regra>"					{update_location; return TAG_RULE_START;}
"</regra>"					{update_location; return TAG_RULE_END;}
"<se>"						{update_location; return TAG_IF_START;}
"</se>"						{update_location; return TAG_IF_END;}
"<entao>"					{update_location; return TAG_THEN;}
"<senao>"					{update_location; return TAG_ELSE;}
"<condicao>"				{update_location; return TAG_CONDITION_START;}
"</condicao>"				{update_location; return TAG_CONDITION_END;}
"<comandos>"				{update_location; return TAG_ACTION_START;}
"</comandos>"				{update_location; return TAG_ACTION_END;}
"<comando>"					{update_location; return TAG_COMMAND_START;}
"</comando>"				{update_location; return TAG_COMMAND_END;}
"<leia_sensor>"				{update_location; return TAG_READ_SENSOR_START;}
"</leia_sensor>"			{update_location; return TAG_READ_SENSOR_END;}
"<escreva_atuador>"			{update_location; return TAG_WRITE_ACTUATOR_START;}
"</escreva_atuador>"		{update_location; return TAG_WRITE_ACTUATOR_END;}
"<mensagem>"				{update_location; return TAG_MESSAGE_START;}
"</mensagem>"				{update_location; return TAG_MESSAGE_END;}

"+"							{
								update_location;
								yylval->arithOp = SUM; 
								return ARITH_OP;
							}

"-"							{	
								update_location;
								yylval->arithOp = SUBTRACTION; 
								return ARITH_OP;
							}

"*"							{
								update_location;
								yylval->arithOp = MULTIPLICATION; 
								return ARITH_OP;
							}

"/"							{	
								update_location;
								yylval->arithOp = DIVISION; 
								return ARITH_OP;
							}

"("							{update_location; return PARENTHESES_START;}
")"							{update_location; return PARENTHESES_END;}

"<"							{
								update_location;
								yylval->compOp = LESS; 
								return COMP_OP;
							}

"<="						{
								update_location;
								yylval->compOp = LESS_EQUAL;
								return COMP_OP;
							}

">"							{
								update_location;
								yylval->compOp = GREATER;
								return COMP_OP;
							}

">="						{
								update_location;
								yylval->compOp = GREATER_EQUAL;
								return COMP_OP;
							}

"<>"						{
								update_location;
								yylval->compOp = DIFFERENT;
								return COMP_OP;
							}

"=="						{
								update_location;
								yylval->compOp = EQUAL;
								return COMP_OP;
							}

"<-"						{
								update_location;
								return ASSIGNMENT_OP;
							}

"NOT"						{
								update_location;
								yylval->logicOp = NOT;
								return LOGIC_OP;
							}

"AND"						{
								update_location;
								yylval->logicOp = AND;
								return LOGIC_OP;
							}

"OR"						{
								update_location;
								yylval->logicOp = OR;
								return LOGIC_OP;
							}

([\+-])?[0-9]+\.[0-9]+				{
								update_location; 
								yylval->number = atof(yytext);
								return NUMBER;
							}

[A-Za-z][A-Za-z0-9_]*		{
								update_location;
								yylval->string = _strdup(yytext);								
								return IDENTIFIER;
							}
[ \t]+                      /* ignora whitespace */;

[\n]                        { yylloc->first_line = yylloc->last_line = yylineno;
                              yylloc->first_column = 1;
                              yylloc->last_column = 0;
                            }

%%